package com.zmn.plat.business.impl.push;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.commons.collections4.ListUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.ltsopensource.core.domain.Job;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto.ResultDTO;
import com.zmn.common.dto.VtDTO;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.office.ExcelUtil;
import com.zmn.common.utils.pager.LayuiPageUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.manager.common.database.annotation.ReadOnlyConnection;
import com.zmn.manager.lts.interfaces.task.TaskManager;
import com.zmn.manager.mq.utils.MQPushUtil;
import com.zmn.mcc.common.dto.dept.DeptDRO;
import com.zmn.mcc.dubbo.interfaces.dept.DeptListRemoteService;
import com.zmn.plat.business.interfaces.push.PushNoticeAppBService;
import com.zmn.plat.common.constant.BaseAreaConsts;
import com.zmn.plat.common.constant.CompanyConsts;
import com.zmn.plat.common.constant.PushConsts;
import com.zmn.plat.common.dictionary.PushDict;
import com.zmn.plat.common.dto.push.PushNoticeAppDRO;
import com.zmn.plat.common.exception.PlatException;
import com.zmn.plat.dubbo.utils.DubboConsts;
import com.zmn.plat.manager.utils.TaskConsts;
import com.zmn.plat.model.entity.area.AreaQuery;
import com.zmn.plat.model.entity.area.BaseArea;
import com.zmn.plat.model.entity.area.CascadeAreaVO;
import com.zmn.plat.model.entity.company.CompanyTypeQuery;
import com.zmn.plat.model.entity.push.notice.*;
import com.zmn.plat.model.vo.push.PushNoticeAppVo;
import com.zmn.plat.services.interfaces.area.BaseAreaService;
import com.zmn.plat.services.interfaces.company.BaseCompanyService;
import com.zmn.plat.services.interfaces.push.notice.*;

import lombok.extern.slf4j.Slf4j;

/**
 * 描述: app 公告管理业务接口实现类
 *
 * @author wangjie
 * @since 2020/3/23
 **/
@Slf4j
@Service
public class PushNoticeAppBServiceImpl implements PushNoticeAppBService {

    private static final String TAG = "app公告管理业务接口实现类";

    @Resource
    PushNoticeAppService pushNoticeAppService;

    @Resource
    BaseAreaService baseAreaService;

    @Resource
    PushNoticeAppPutAppService pushNoticeAppPutAppService;

    @Resource
    BaseCompanyService baseCompanyService;

    @Resource
    PushNoticeAppPutPlatService pushNoticeAppPutPlatService;

    @Resource
    PushNoticeAppPutCompanyTypeService pushNoticeAppPutCompanyTypeService;

    @Resource
    PushNoticeAppPutCompanyService pushNoticeAppPutCompanyService;

    @Resource
    PushNoticeAppPutProvinceService pushNoticeAppPutProvinceService;

    @Resource
    PushNoticeAppPutCityService pushNoticeAppPutCityService;

    @Resource
    PushNoticeAppPutCountyService pushNoticeAppPutCountyService;

//    @Resource
//    PushNoticeAppPutEngineerGroupService pushNoticeAppPutEngineerGroupService;

    @Resource
    PushNoticeAppPutEngineerService pushNoticeAppPutEngineerService;

    @Resource
    TaskManager taskManager;

    @Reference(version = DubboConsts.INTERFACE_VERSION, check = false)
    DeptListRemoteService deptListRemoteService;

    /**
     * 描述: 分页查询
     *
     * @param query 查询对象
     * @return java.util.List<com.zmn.plat.model.entity.push.notice.PushNoticeApp>
     * @author wangjie
     * @since 2020/3/23
     **/
    @Override
    public List<PushNoticeAppVo> listQueryByPage(PushNoticeAppQuery query) {

        if (!StringUtil.isBlank(query.getBeginTimeStr())) {
            String[] strings = LayuiPageUtil.dateIntercept(query.getBeginTimeStr());
            query.setBeginTimeEnd(DateUtil.getDateEnd(DateUtil.parse(strings[1], DateUtil.FORMAT_DATE)));
            query.setBeginTimeStart(DateUtil.parse(strings[0], DateUtil.FORMAT_DATE));
        }
        if (!StringUtil.isBlank(query.getCreateTimeStr())) {
            String[] strings = LayuiPageUtil.dateIntercept(query.getCreateTimeStr());
            query.setCreateTimeEnd(DateUtil.getDateEnd(DateUtil.parse(strings[1], DateUtil.FORMAT_DATE)));
            query.setCreateTimeStart(DateUtil.parse(strings[0], DateUtil.FORMAT_DATE));
        }

        Integer count = pushNoticeAppService.countPageByQuery(query);
        query.setTotalCount(count);

        Map<Integer, String> pushTypeMap = PushDict.vtDtoToMap(PushDict.listPushType());
        Map<Integer, String> noticeCategoryMap = PushDict.vtDtoToMap(PushDict.listPushNoticeCategory());
        Map<Integer, String> putAppMap = PushDict.vtDtoToMap(PushDict.listPushApp());

        List<PushNoticeApp> pushNoticeAppList = Optional.ofNullable(pushNoticeAppService.listPageByQuery(query)).orElse(Collections.emptyList());

        List<Integer> noticeIdList = pushNoticeAppList.stream().map(PushNoticeApp::getId).distinct().collect(Collectors.toList());

        Map<Integer, List<PushNoticeAppPutApp>> putApp = Optional.ofNullable(pushNoticeAppPutAppService.listByNoticeIdList(noticeIdList)).orElse(Collections.emptyList()).stream()
                .collect(Collectors.groupingBy(PushNoticeAppPutApp::getNoticeAppId));

        return pushNoticeAppList.stream().map(mm -> BeanMapper.map(mm, PushNoticeAppVo.class)).peek(pp -> {
            pp.setPutTypeStr(Optional.ofNullable(pushTypeMap.get(pp.getPutType())).orElse(""));
            pp.setNoticeCategoryStr(Optional.ofNullable(noticeCategoryMap.get(pp.getNoticeCategoryId())).orElse(""));
            pp.setBeginTimeStr(Objects.isNull(pp.getBeginTime()) ? "" : DateUtil.toString(pp.getBeginTime(), DateUtil.FORMAT_DEFAULT));
            pp.setEndTimeStr(Objects.isNull(pp.getEndTime()) ? "" : DateUtil.toString(pp.getEndTime(), DateUtil.FORMAT_DEFAULT));
            pp.setCreateTimeStr(Objects.isNull(pp.getCreateTime()) ? "" : DateUtil.toString(pp.getCreateTime(), DateUtil.FORMAT_DEFAULT));
            pp.setDeptNameStr(Optional.ofNullable(pp.getDeptOneName()).orElse("") + "/" + Optional.ofNullable(pp.getDeptTowName()).orElse(""));
            // 设置发放平台
            List<PushNoticeAppPutApp> pushNoticePutAppList = Optional.ofNullable(putApp.get(pp.getId())).orElse(Collections.emptyList());
            List<String> putAppList = pushNoticePutAppList.stream().map(mm -> putAppMap.get(mm.getPutApp())).collect(Collectors.toList());
            pp.setPutApp(Joiner.on(",").join(putAppList));

        }).collect(Collectors.toList());
    }

    /**
     * 描述: 保存或者修改
     *
     * @param pushNoticeAppVo app公告对象
     * @param operator        操作员
     * @return com.zmn.common.dto2.ResponseDTO<java.lang.String>
     * @author wangjie
     * @since 2020/3/23
     **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveAndEdit(PushNoticeAppVo pushNoticeAppVo, String operator) {

        if (Objects.isNull(pushNoticeAppVo)) {
            log.error("[{}],保存或者修改，入参为null", TAG);
            throw new PlatException("操作失败,程序异常!");
        }
        if (NumberUtil.isNotNullOrZero(pushNoticeAppVo.getId())) {
            // 修改
            pushNoticeAppService.updateByKey(pushNoticeAppVo, operator);
            this.initPutNoticeLinkedData(pushNoticeAppVo.getId(), pushNoticeAppVo, operator);
        } else {
            // 新增
            this.add(pushNoticeAppVo, operator);
        }
        this.submitPushMsgTask(pushNoticeAppVo, operator);

    }

    /**
     * 描述: 上传导入excel
     *
     * @param multipartFile 文件对象
     * @param noticeId      公告id
     * @param operator      操作
     * @return com.zmn.common.dto2.ResponseDTO<java.lang.String>
     * @author wangjie
     * @since 2020/3/30
     **/
    @Override
    public String importExcel(MultipartFile multipartFile, Integer noticeId, String operator) {

        if (Objects.isNull(multipartFile) || NumberUtil.isNullOrZero(noticeId)) {
            log.error("[{}],导入excel失败，文件对象为空 或者 noticeId 为0 或者空", TAG);
            throw new PlatException("导入excel失败，文件对象为空");
        }
        int failureLine = 0;
        try {
            List read = ExcelUtil.read(multipartFile.getInputStream(), true, false);
            ArrayList<PushNoticeAppPutEngineer> pushNoticeAppPutEngineerArrayList = Lists.newArrayListWithExpectedSize(read.size());
            for (Object readList : read) {
                ArrayList arrayList = (ArrayList) readList;
                PushNoticeAppPutEngineer pushNoticeAppPutEngineer = new PushNoticeAppPutEngineer();
                Object objEngineerId = Optional.ofNullable(arrayList.get(1)).orElse(null);
                Object objEngineerName = Optional.ofNullable(arrayList.get(2)).orElse(null);

                if (Objects.nonNull(objEngineerId)) {
                    try {
                        Integer engineerId = Double.valueOf(objEngineerId.toString()).intValue();
                        pushNoticeAppPutEngineer.setEngineerId(engineerId);
                        pushNoticeAppPutEngineer.setCreater(operator);
                        pushNoticeAppPutEngineer.setCreateTime(DateUtil.getNow());
                        pushNoticeAppPutEngineer.setEngineerName(Optional.ofNullable(objEngineerName).orElse("").toString());
                        pushNoticeAppPutEngineer.setNoticeAppId(noticeId);
                        pushNoticeAppPutEngineerArrayList.add(pushNoticeAppPutEngineer);
                    } catch (NumberFormatException e) {
                        log.error("[{}],格式化师傅id异常，跳过该行数据！,objEngineerId:{}", TAG, objEngineerId, e);
                        failureLine++;
                    }
                } else {
                    failureLine++;
                }
            }
            pushNoticeAppPutEngineerService.deleteByNoticeId(noticeId);
            pushNoticeAppPutEngineerService.insertBatch(pushNoticeAppPutEngineerArrayList);
            if (CollectionUtil.isNullOrEmpty(pushNoticeAppPutEngineerArrayList) && failureLine > 0) {
                throw new PlatException("导入数据异常:{0}条,失败{" + failureLine + "}条");
            } else {
                return "成功导入数据:{" + pushNoticeAppPutEngineerArrayList.size() + "}条,失败{" + failureLine + "}条";
            }
        } catch (IOException e) {
            log.error("[{}],读取excel文件失败！", TAG, e);
            throw new PlatException("读取excel文件失败");
        }
    }

    /**
     * 描述: 提交定时任务
     *
     * @param noticeId 公告id
     * @param operator 操作员
     * @author wangjie
     * @since 2020/4/1
     **/
    @Override
    public void submitPushMsgTask(Integer noticeId, String operator) {
        PushNoticeApp pushNoticeApp = Optional.ofNullable(pushNoticeAppService.findByKey(noticeId)).orElse(new PushNoticeAppVo());
        this.submitPushMsgTask(pushNoticeApp, operator);
    }

    /**
     * 描述: 新增
     *
     * @param pushNoticeAppVo app公告对象
     * @param operator        操作员
     * @author wangjie
     * @since 2020/3/23
     **/
    private void add(PushNoticeAppVo pushNoticeAppVo, String operator) {

        PushNoticeApp pushNoticeApp = BeanMapper.map(pushNoticeAppVo, PushNoticeApp.class);
        pushNoticeApp.setStatus(GlobalConsts.NO);
        pushNoticeApp.setSort(GlobalConsts.NO);
        pushNoticeAppService.insert(pushNoticeApp, operator);
        this.initPutNoticeLinkedData(pushNoticeApp.getId(), pushNoticeAppVo, operator);
    }

    /**
     * 描述: 通过父级id查询部门数据
     *
     * @param pid 父级id
     * @author wangjie
     * @since 2020/7/6/15:31
     **/
    @Override
    @Cacheable(cacheNames = "redis1d", key = "'notice:dept:pid' + #pid", unless = "#reslut == null || #result.size() <= 0")
    public List<VtDTO> listCacheDeptByPid(Integer pid) {

        if (NumberUtil.isNullOrZero(pid)) {
            return Collections.emptyList();
        }
        ResponseDTO<List<DeptDRO>> response = deptListRemoteService.listDeptByParentId(pid, GlobalConsts.YES);
        if (!response.isSuccess()) {
            log.error("[{}],msg:{}", TAG, response.getMessage());
            return Collections.emptyList();
        }
        return Optional.ofNullable(response.getData()).orElse(Collections.emptyList()).stream().map(mm -> new VtDTO(mm.getDeptId(), mm.getDeptName())).collect(Collectors.toList());
    }

    /**
     * 描述: 全量获取一级部门数据
     *
     * @param deptLeave 部门级别
     * @return java.util.List<com.zmn.common.dto.VtDTO>
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    @Cacheable(cacheNames = "redis1d", key = "'notice:dept:deptLeave' + #deptLeave", unless = "#reslut == null || #result.size() <= 0")
    public List<VtDTO> listCacheOneDeptByLeave(Integer deptLeave) {

        if (NumberUtil.isNullOrZero(deptLeave)) {
            return Collections.emptyList();
        }
        ResponseDTO<List<DeptDRO>> response = deptListRemoteService.listDeptByLevelAndStatus(deptLeave, GlobalConsts.YES);
        if (!response.isSuccess()) {
            log.error("[{}],msg:{}", TAG, response.getMessage());
            return Collections.emptyList();
        }
        return Optional.ofNullable(response.getData()).orElse(Collections.emptyList()).stream().map(mm -> new VtDTO(mm.getDeptId(), mm.getDeptName())).collect(Collectors.toList());
    }

    /**
     * 描述: 获取所有省份 使用了缓存
     *
     * @return java.util.List<com.zmn.common.dto.VtDTO>
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    @Cacheable(cacheNames = "redis1d", key = "'notice:area:allprovince'")
    public List<VtDTO> listAllCacheProvince() {

        return this.listProvinceCascadeAreaVOList().stream().map(mm -> new VtDTO(mm.getValue(), mm.getName())).collect(Collectors.toList());
    }

    /**
     * 描述:获取所有城市 使用了缓存
     *
     * @return java.util.List<com.zmn.common.dto.VtDTO>
     * @author wangjie
     * @since 2020/3/24 List<List<CascadeAreaVO>> collect =
     **/
    @Override
    @Cacheable(cacheNames = "redis1d", key = "'notice:area:allcity'")
    public List<VtDTO> listAllCacheCity() {

        return this.listProvinceCascadeAreaVOList().stream().map(CascadeAreaVO::getChildren).flatMap(Collection::stream).map(mm -> new VtDTO(mm.getValue(), mm.getName())).collect(Collectors.toList());
    }

    /**
     * 描述: 根据省份id查询缓存的城市数据
     *
     * @param provinceIdList 省份id
     * @return java.util.List<com.zmn.common.dto.VtDTO>
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    @Cacheable(cacheNames = "redis1d", key = "'notice:area:province:pid:' + #provinceIdList")
    public List<VtDTO> listCacheCityByProvinceId(List<Integer> provinceIdList) {

        return this.listProvinceCascadeAreaVOList().stream().filter(ff -> provinceIdList.contains(ff.getValue())).map(CascadeAreaVO::getChildren).flatMap(Collection::stream)
                .map(mm -> new VtDTO(mm.getValue(), mm.getName())).collect(Collectors.toList());
    }

    /**
     * 描述: 获取所有区县 使用缓存
     *
     * @return java.util.List<com.zmn.common.dto.VtDTO>
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    @Cacheable(cacheNames = "redis1d", key = "'notice:area:allcounty'")
    public List<VtDTO> listAllCacheCounty() {

        Map<Integer, List<VtDTO>> countyMaps = this.listAllCountyToMap();
        return countyMaps.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
    }

    /**
     * 描述: 根据城市id查询缓存的区县数据
     *
     * @param cityIdList 城市id集合
     * @return java.util.List<com.zmn.common.dto.VtDTO>
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    @Cacheable(cacheNames = "redis1d", key = "'notice:area:county:pid' + #cityIdList")
    public List<VtDTO> listCacheCountyByCityId(List<Integer> cityIdList) {

        Map<Integer, List<VtDTO>> countyMaps = this.listAllCountyToMap();
        List<VtDTO> countyLists = Lists.newArrayList();
        cityIdList.forEach(item -> {
            List<VtDTO> vtList = countyMaps.get(item);
            if (CollectionUtil.isNotNullOrEmpty(vtList)) {
                countyLists.addAll(vtList);
            }
        });
        return countyLists;
    }

    /**
     * 描述: 根据平台标识公司类型查询子公司数据
     *
     * @param types 公司类型
     * @param plats 平台标识
     * @return java.util.List<com.zmn.common.dto.VtDTO>
     * @author wangjie
     * @since 2020/3/25
     **/
    @Override
    public List<VtDTO> listCompanyByTypeAndPlat(List<Integer> types, List<Integer> plats) {

        if (CollectionUtil.isNullOrEmpty(types) || CollectionUtil.isNullOrEmpty(plats)) {
            return Collections.emptyList();
        }

        List<CompanyTypeQuery> companyTypeQueryList = types.stream().map(m -> new CompanyTypeQuery(m, CompanyConsts.COMPANY_TYPE_CHILD_DEFAULT)).collect(Collectors.toList());

        return Optional.ofNullable(baseCompanyService.listCompanyByTypesAndPlats(companyTypeQueryList, plats)).orElse(Collections.emptyList()).stream()
                .map(mm -> new VtDTO(mm.getCompanyId(), mm.getName(), mm.getStatus())).collect(Collectors.toList());
    }

    /**
     * 描述: 获取级联的省、市信息
     *
     * @return java.util.List<com.zmn.plat.model.entity.area.CascadeAreaVO>
     * @author wangjie
     * @since 2020/3/24
     **/
    @Cacheable(cacheNames = "redis1d", key = "'notice:area:province:city'")
    public List<CascadeAreaVO> listProvinceCascadeAreaVOList() {

        return Optional.ofNullable(baseAreaService.getProvinceCascadeAreaVOList()).orElse(Collections.emptyList());
    }

    /**
     * 描述:通过noticeId 查询关联数据
     *
     * @param noticeId App公告配置id
     * @return java.util.List<com.zmn.plat.model.vo.push.PushNoticeAppVo>
     * @author wangjie
     * @since 2020/3/27
     **/
    @Override
    public PushNoticeAppVo listNoticeAppLinkedData(Integer noticeId) {

        PushNoticeAppVo pushNoticeAppVo = new PushNoticeAppVo();

        if (NumberUtil.isNullOrZero(noticeId)) {
            return pushNoticeAppVo;
        }
        // 推送app数据
        List<PushNoticeAppPutApp> pushNoticeAppPutApps = Optional.ofNullable(pushNoticeAppPutAppService.listByNoticeId(noticeId)).orElse(Collections.emptyList());
        List<VtDTO> putAppList = pushNoticeAppPutApps.stream().map(mm -> new VtDTO(mm.getPutApp(), mm.getPutApp().toString())).collect(Collectors.toList());
        pushNoticeAppVo.setPutAppList(putAppList);
        // 推送平台
        List<PushNoticeAppPutPlat> pushNoticeAppPutPlatList = Optional.ofNullable(pushNoticeAppPutPlatService.listByNoticeId(noticeId)).orElse(Collections.emptyList());
        List<VtDTO> putPlatList = pushNoticeAppPutPlatList.stream().map(mm -> new VtDTO(mm.getPutPlat(), mm.getPutPlat().toString())).collect(Collectors.toList());
        pushNoticeAppVo.setPutPlatList(putPlatList);
        // 推送公司类型
        List<PushNoticeAppPutCompanyType> pushNoticeAppPutCompanyTypes = Optional.ofNullable(pushNoticeAppPutCompanyTypeService.listByNoticeId(noticeId)).orElse(Collections.emptyList());
        List<VtDTO> putCompanyTypeList = pushNoticeAppPutCompanyTypes.stream().map(mm -> new VtDTO(mm.getPutCompanyType(), mm.getPutCompanyType().toString())).collect(Collectors.toList());
        pushNoticeAppVo.setPutCompanyTypeList(putCompanyTypeList);
        // 推送公司
        List<PushNoticeAppPutCompany> pushNoticeAppPutCompanies = Optional.ofNullable(pushNoticeAppPutCompanyService.listByNoticeId(noticeId)).orElse(Collections.emptyList());
        List<VtDTO> putCompanyList = pushNoticeAppPutCompanies.stream().map(mm -> new VtDTO(mm.getPutCompanyId(), mm.getPutCompanyName())).collect(Collectors.toList());
        pushNoticeAppVo.setPutCompanyList(putCompanyList);
        // 推送省份
        List<PushNoticeAppPutProvince> pushNoticeAppPutProvinces = Optional.ofNullable(pushNoticeAppPutProvinceService.listByNoticeId(noticeId)).orElse(Collections.emptyList());
        List<VtDTO> putProvinceList = pushNoticeAppPutProvinces.stream().map(mm -> new VtDTO(mm.getPutProvinceId(), mm.getPutProvinceName())).collect(Collectors.toList());
        pushNoticeAppVo.setPutProvinceList(putProvinceList);
        // 推送城市
        List<PushNoticeAppPutCity> pushNoticeAppPutCities = Optional.ofNullable(pushNoticeAppPutCityService.listByNoticeId(noticeId)).orElse(Collections.emptyList());
        List<VtDTO> putCityList = pushNoticeAppPutCities.stream().map(mm -> new VtDTO(mm.getPutCityId(), mm.getPutCityName())).collect(Collectors.toList());
        pushNoticeAppVo.setPutCityList(putCityList);
        // 推送区县
        List<PushNoticeAppPutCounty> pushNoticeAppPutCounties = Optional.ofNullable(pushNoticeAppPutCountyService.listByNoticeId(noticeId)).orElse(Collections.emptyList());
        List<VtDTO> putCountyList = pushNoticeAppPutCounties.stream().map(mm -> new VtDTO(mm.getPutCountyId(), mm.getPutCountyName())).collect(Collectors.toList());
        pushNoticeAppVo.setPutCountyList(putCountyList);
        // 推送工程师分组
//        List<PushNoticeAppEngineerPutGroup> pushNoticeAppEngineerPutGroups = Optional.ofNullable(pushNoticeAppPutEngineerGroupService.listByNoticeId(noticeId)).orElse(Collections.emptyList());
//        List<VtDTO> putEngineerGroupList = pushNoticeAppEngineerPutGroups.stream().map(mm -> new VtDTO(mm.getPutEngineerGroup(), mm.getPutEngineerGroup().toString())).collect(Collectors.toList());
//        pushNoticeAppVo.setPutEngineerGroupList(putEngineerGroupList);
        return pushNoticeAppVo;
    }

    /**
     * 描述: 获取所有区县id
     *
     * @return java.util.HashMap<java.lang.Integer ,   java.util.List   <   com.zmn.common.dto.VtDTO>> MAP<cityId,countyList>
     * @author wangjie
     * @since 2020/3/24
     **/
    @Cacheable(cacheNames = "redis1d", key = "'notice:area:county'")
    public Map<Integer, List<VtDTO>> listAllCountyToMap() {

        AreaQuery areaQuery = new AreaQuery();
        areaQuery.setLevel(BaseAreaConsts.AREA_LEVEL_FOUR);

        List<BaseArea> baseAreas = Optional.ofNullable(baseAreaService.listByQuery(areaQuery)).orElse(Collections.emptyList());
        Map<Integer, List<BaseArea>> collect = baseAreas.stream().collect(Collectors.groupingBy(BaseArea::getParentId));
        HashMap<Integer, List<VtDTO>> hashMap = Maps.newHashMapWithExpectedSize(baseAreas.size());
        collect.forEach((k, v) -> {
            List<VtDTO> countyList = v.stream().map(mm -> new VtDTO(mm.getAreaId(), mm.getName(), mm.getStatus())).collect(Collectors.toList());
            hashMap.put(k, countyList);
        });
        return hashMap;
    }

    /**
     * 描述: 初始化app公告关联数据
     *
     * @param noticeId        公告id
     * @param pushNoticeAppVo app公告数据
     * @param operator        操作人
     * @author wangjie
     * @since 2020/3/27
     **/
    private void initPutNoticeLinkedData(Integer noticeId, PushNoticeAppVo pushNoticeAppVo, String operator) {
        // 推送App
        this.initPutApp(noticeId, pushNoticeAppVo.getPutAppList(), operator);
        // 推送平台
        this.initPutPlat(noticeId, pushNoticeAppVo.getPutPlatList(), operator);
        // 推送公司类型
        this.initPutCompanyType(noticeId, pushNoticeAppVo.getPutCompanyTypeList(), operator);
        // 推送公司
        this.initPutCompany(noticeId, pushNoticeAppVo.getPutCompanyList(), operator);
        // 推送省份
        this.initPutProvince(noticeId, pushNoticeAppVo.getPutProvinceList(), operator);
        // 推送城市
        this.initPutCity(noticeId, pushNoticeAppVo.getPutCityList(), operator);
        // 推送区县
        this.initPutCounty(noticeId, pushNoticeAppVo.getPutCountyList(), operator);
        // 推送工程师分组
//        this.initPutEngineerGroup(noticeId, pushNoticeAppVo.getPutEngineerGroupList(), operator);
    }

    /**
     * 描述:初始化推送app数据 先删后增
     *
     * @param noticeId   公告id
     * @param putAppList 推送app数据
     * @param operator   操作人
     * @author wangjie
     * @since 2020/3/27
     **/
    private void initPutApp(Integer noticeId, List<VtDTO> putAppList, String operator) {

        pushNoticeAppPutAppService.deleteByNoticeId(noticeId);
        if (CollectionUtil.isNullOrEmpty(putAppList)) {
            return;
        }
        if (CollectionUtil.isNotNullOrEmpty(putAppList)) {
            List<PushNoticeAppPutApp> pushNoticePutAppList = putAppList.stream().map(mm -> {
                PushNoticeAppPutApp pushNoticePutApp = new PushNoticeAppPutApp();
                pushNoticePutApp.setCreateTime(DateUtil.getNow());
                pushNoticePutApp.setCreater(operator);
                pushNoticePutApp.setNoticeAppId(noticeId);
                pushNoticePutApp.setPutApp(mm.getValue());
                pushNoticePutApp.setStatus(GlobalConsts.YES);
                return pushNoticePutApp;
            }).collect(Collectors.toList());
            pushNoticeAppPutAppService.insertBatch(pushNoticePutAppList);
        }
    }

    /**
     * 描述: 初始化推送平台数据 先删后增
     *
     * @param noticeId    公告id
     * @param putPlatList 推送平台数据
     * @param operator    操作人
     * @author wangjie
     * @since 2020/3/27
     **/
    private void initPutPlat(Integer noticeId, List<VtDTO> putPlatList, String operator) {

        pushNoticeAppPutPlatService.deleteByNoticeId(noticeId);
        if (CollectionUtil.isNullOrEmpty(putPlatList)) {
            return;
        }
        List<PushNoticeAppPutPlat> pushNoticeAppPutPlatList = putPlatList.stream().map(mm -> {
            PushNoticeAppPutPlat pushNoticeAppPutPlat = new PushNoticeAppPutPlat();
            pushNoticeAppPutPlat.setNoticeAppId(noticeId);
            pushNoticeAppPutPlat.setPutPlat(mm.getValue());
            return pushNoticeAppPutPlat;
        }).collect(Collectors.toList());
        pushNoticeAppPutPlatService.insertBatch(pushNoticeAppPutPlatList, operator);
    }

    /**
     * 描述: 初始化推送公司类型数据 先删后增
     *
     * @param noticeId       公告id
     * @param putCompanyType 推送公司类型
     * @param operator       操作人
     * @author wangjie
     * @since 2020/3/27
     **/
    private void initPutCompanyType(Integer noticeId, List<VtDTO> putCompanyType, String operator) {

        pushNoticeAppPutCompanyTypeService.deleteByNoticeId(noticeId);
        if (CollectionUtil.isNullOrEmpty(putCompanyType)) {
            return;
        }
        List<PushNoticeAppPutCompanyType> pushNoticeAppPutPlatList = putCompanyType.stream().map(mm -> {
            PushNoticeAppPutCompanyType companyType = new PushNoticeAppPutCompanyType();
            companyType.setNoticeAppId(noticeId);
            companyType.setPutCompanyType(mm.getValue());
            companyType.setCreater(operator);
            companyType.setCreateTime(DateUtil.getNow());
            companyType.setStatus(GlobalConsts.YES);
            return companyType;
        }).collect(Collectors.toList());
        pushNoticeAppPutCompanyTypeService.insertBatch(pushNoticeAppPutPlatList);
    }

    /**
     * 描述: 初始化推送公司数据 先删后增
     *
     * @param noticeId   公告id
     * @param putCompany 推送公司
     * @param operator   操作人
     * @author wangjie
     * @since 2020/3/27
     **/
    private void initPutCompany(Integer noticeId, List<VtDTO> putCompany, String operator) {

        pushNoticeAppPutCompanyService.deleteByNoticeId(noticeId);
        if (CollectionUtil.isNullOrEmpty(putCompany)) {
            return;
        }
        List<PushNoticeAppPutCompany> pushNoticeAppPutCompanies = putCompany.stream().map(mm -> {
            PushNoticeAppPutCompany pushNoticeAppPutCompany = new PushNoticeAppPutCompany();
            pushNoticeAppPutCompany.setCreater(operator);
            pushNoticeAppPutCompany.setCreateTime(DateUtil.getNow());
            pushNoticeAppPutCompany.setNoticeAppId(noticeId);
            pushNoticeAppPutCompany.setPutCompanyId(mm.getValue());
            pushNoticeAppPutCompany.setPutCompanyName(mm.getText());
            pushNoticeAppPutCompany.setStatus(GlobalConsts.YES);
            return pushNoticeAppPutCompany;
        }).collect(Collectors.toList());
        pushNoticeAppPutCompanyService.insertBatch(pushNoticeAppPutCompanies);
    }

    /**
     * 描述: 初始化推送省份数据 先删后增
     *
     * @param noticeId    公告id
     * @param putProvince 推送省份
     * @param operator    操作人
     * @author wangjie
     * @since 2020/3/27
     **/
    private void initPutProvince(Integer noticeId, List<VtDTO> putProvince, String operator) {

        pushNoticeAppPutProvinceService.deleteByNoticeId(noticeId);
        if (CollectionUtil.isNullOrEmpty(putProvince)) {
            return;
        }
        List<PushNoticeAppPutProvince> pushNoticeAppPutProvinces = putProvince.stream().map(mm -> {
            PushNoticeAppPutProvince pushNoticeAppPutProvince = new PushNoticeAppPutProvince();
            pushNoticeAppPutProvince.setCreater(operator);
            pushNoticeAppPutProvince.setCreateTime(DateUtil.getNow());
            pushNoticeAppPutProvince.setNoticeAppId(noticeId);
            pushNoticeAppPutProvince.setPutProvinceId(mm.getValue());
            pushNoticeAppPutProvince.setPutProvinceName(mm.getText());
            pushNoticeAppPutProvince.setStatus(GlobalConsts.YES);
            return pushNoticeAppPutProvince;
        }).collect(Collectors.toList());
        pushNoticeAppPutProvinceService.insertBatch(pushNoticeAppPutProvinces);
    }

    /**
     * 描述: 初始化推送城市数据 先删后增
     *
     * @param noticeId 公告id
     * @param putCity  推送城市
     * @param operator 操作人
     * @author wangjie
     * @since 2020/3/27
     **/
    private void initPutCity(Integer noticeId, List<VtDTO> putCity, String operator) {

        pushNoticeAppPutCityService.deleteByNoticeId(noticeId);
        if (CollectionUtil.isNullOrEmpty(putCity)) {
            return;
        }
        List<PushNoticeAppPutCity> pushNoticeAppPutCityList = putCity.stream().map(mm -> {
            PushNoticeAppPutCity pushNoticeAppPutCity = new PushNoticeAppPutCity();
            pushNoticeAppPutCity.setCreater(operator);
            pushNoticeAppPutCity.setCreateTime(DateUtil.getNow());
            pushNoticeAppPutCity.setNoticeAppId(noticeId);
            pushNoticeAppPutCity.setPutCityId(mm.getValue());
            pushNoticeAppPutCity.setPutCityName(mm.getText());
            pushNoticeAppPutCity.setStatus(GlobalConsts.YES);
            return pushNoticeAppPutCity;
        }).collect(Collectors.toList());
        pushNoticeAppPutCityService.insertBatch(pushNoticeAppPutCityList);
    }

    /**
     * 描述: 初始化推送区县数据 先删后增
     *
     * @param noticeId  公告id
     * @param putCounty 推送区县
     * @param operator  操作人
     * @author wangjie
     * @since 2020/3/27
     **/
    private void initPutCounty(Integer noticeId, List<VtDTO> putCounty, String operator) {

        pushNoticeAppPutCountyService.deleteByNoticeId(noticeId);
        if (CollectionUtil.isNullOrEmpty(putCounty)) {
            return;
        }
        List<PushNoticeAppPutCounty> pushNoticeAppPutCountyList = putCounty.stream().map(mm -> {
            PushNoticeAppPutCounty pushNoticeAppPutCounty = new PushNoticeAppPutCounty();
            pushNoticeAppPutCounty.setCreater(operator);
            pushNoticeAppPutCounty.setCreateTime(DateUtil.getNow());
            pushNoticeAppPutCounty.setNoticeAppId(noticeId);
            pushNoticeAppPutCounty.setPutCountyId(mm.getValue());
            pushNoticeAppPutCounty.setPutCountyName(mm.getText());
            pushNoticeAppPutCounty.setStatus(GlobalConsts.YES);
            return pushNoticeAppPutCounty;
        }).collect(Collectors.toList());
        pushNoticeAppPutCountyService.insertBatch(pushNoticeAppPutCountyList);
    }

//    /**
//     * 描述: 初始化推送工程师分组数据 先删后增
//     *
//     * @param noticeId         公告id
//     * @param putEngineerGroup 推送工程师分组
//     * @param operator         操作人
//     * @author wangjie
//     * @since 2020/3/27
//     **/
//    private void initPutEngineerGroup(Integer noticeId, List<VtDTO> putEngineerGroup, String operator) {
//
//        pushNoticeAppPutEngineerGroupService.deleteByNoticeId(noticeId);
//        if (CollectionUtil.isNullOrEmpty(putEngineerGroup)) {
//            return;
//        }
//        List<PushNoticeAppEngineerPutGroup> pushNoticeAppEngineerPutGroupList = putEngineerGroup.stream().map(mm -> {
//            PushNoticeAppEngineerPutGroup pushNoticeAppEngineerPutGroup = new PushNoticeAppEngineerPutGroup();
//            pushNoticeAppEngineerPutGroup.setCreater(operator);
//            pushNoticeAppEngineerPutGroup.setCreateTime(DateUtil.getNow());
//            pushNoticeAppEngineerPutGroup.setNoticeAppId(noticeId);
//            pushNoticeAppEngineerPutGroup.setPutEngineerGroup(mm.getValue());
//            pushNoticeAppEngineerPutGroup.setStatus(GlobalConsts.YES);
//            return pushNoticeAppEngineerPutGroup;
//        }).collect(Collectors.toList());
//        pushNoticeAppPutEngineerGroupService.insertBatch(pushNoticeAppEngineerPutGroupList);
//    }

    /**
     * 描述: 提交定时任务，在这个时间点触发消息推送
     *
     * @param pushNoticeApp 发送消息对象
     * @param operator      操作人
     * @author wangjie
     * @since 2020/3/31
     **/
    private void submitPushMsgTask(PushNoticeApp pushNoticeApp, String operator) {

        String sNoticeId = NumberUtil.isNullOrZero(pushNoticeApp.getId()) ? "0" : pushNoticeApp.getId().toString();
        String taskId = TaskConsts.TASK_ID_PUSH_NOTICE_MSG + ":" + sNoticeId;

        if (!Objects.equals(pushNoticeApp.getPutType(), PushConsts.PUT_TYPE_PUSH_MSG)) {
            log.error("[{}],推送消息到app状态不符合,putType:{},operator:{}", TAG, pushNoticeApp.getPutType(), operator);
            return;
        }
        if (!Objects.equals(pushNoticeApp.getStatus(), GlobalConsts.YES)) {
            log.error("[{}],推送消息到数据状态为禁用,status:{},operator:{}", TAG, pushNoticeApp.getStatus(), operator);
            taskManager.cancelTask(taskId);
            return;
        }
        Job job = new Job();
        job.setTaskId(taskId);
        job.setParam(TaskManager.SHARD_FIELD, TaskConsts.TASK_ID_PUSH_NOTICE_MSG);
        job.setParam("noticeId", sNoticeId);
        job.setParam("operator", operator);
        job.setTriggerDate(pushNoticeApp.getBeginTime());
        job.setReplaceOnExist(true);
        taskManager.submitTask(job);
        log.info("[{}],提交app公告推送消息定时任务成功,time:{},operator:{}", TAG, pushNoticeApp.getBeginTime(), operator);
    }

    /**
     * 描述: 找到需要向工程师app发送通知的 工程师数据
     *
     * @return java.util.List<java.lang.Integer>
     * @author wangjie
     * @since 2020/3/31
     **/
    private List<Integer> listPushNoticeToEngineer(Integer noticeId, Integer engineerId) {

        PushNoticeAppSearchEngineerQuery pushNoticeAppSearchEngineerQuery = new PushNoticeAppSearchEngineerQuery();
        // 查询工程师所在平台
        List<PushNoticeAppPutPlat> pushNoticeAppPutPlatList = pushNoticeAppPutPlatService.listByNoticeId(noticeId);
        pushNoticeAppSearchEngineerQuery.setPushNoticeAppPutPlatList(pushNoticeAppPutPlatList);
        // 查询工程师所在公司类型
        List<PushNoticeAppPutCompanyType> pushNoticeAppPutCompanyTypes = pushNoticeAppPutCompanyTypeService.listByNoticeId(noticeId);
        pushNoticeAppSearchEngineerQuery.setPushNoticeAppPutCompanyTypes(pushNoticeAppPutCompanyTypes);
        // 查询工程师所在公司
        List<PushNoticeAppPutCompany> pushNoticeAppPutCompanyList = pushNoticeAppPutCompanyService.listByNoticeId(noticeId);
        pushNoticeAppSearchEngineerQuery.setPushNoticeAppPutCompanyList(pushNoticeAppPutCompanyList);
        // 查询工程师所在省份
        List<PushNoticeAppPutProvince> pushNoticeAppPutProvinces = pushNoticeAppPutProvinceService.listByNoticeId(noticeId);
        pushNoticeAppSearchEngineerQuery.setPushNoticeAppPutProvinces(pushNoticeAppPutProvinces);
        // 查询工程师所在城市
        List<PushNoticeAppPutCity> pushNoticeAppPutCities = pushNoticeAppPutCityService.listByNoticeId(noticeId);
        pushNoticeAppSearchEngineerQuery.setPushNoticeAppPutCities(pushNoticeAppPutCities);
        // 查询工程师所在区域
        List<PushNoticeAppPutCounty> pushNoticeAppPutCounties = pushNoticeAppPutCountyService.listByNoticeId(noticeId);
        pushNoticeAppSearchEngineerQuery.setPushNoticeAppPutCounties(pushNoticeAppPutCounties);
        // 查询工程师所在分组
//        List<PushNoticeAppEngineerPutGroup> pushNoticeAppEngineerPutGroups = pushNoticeAppPutEngineerGroupService.listByNoticeId(noticeId);
//        pushNoticeAppSearchEngineerQuery.setPushNoticeAppEngineerPutGroups(pushNoticeAppEngineerPutGroups);
        // 查询导入的工程师
        List<PushNoticeAppPutEngineer> importEngineer = Optional.ofNullable(pushNoticeAppPutEngineerService.listByNoticeId(noticeId)).orElse(Collections.emptyList());
        if (CollectionUtil.isNotNullOrEmpty(importEngineer)) {
            List<Integer> engineerIdList = importEngineer.stream().map(PushNoticeAppPutEngineer::getEngineerId).distinct().collect(Collectors.toList());
            pushNoticeAppSearchEngineerQuery.setEngineerIdList(engineerIdList);
        }
        if (Objects.nonNull(engineerId)) {
            pushNoticeAppSearchEngineerQuery.setEngineerId(engineerId);
        }

        boolean meetQuery = CollectionUtil.isNullOrEmpty(pushNoticeAppSearchEngineerQuery.getPushNoticeAppPutCompanyList())
                && CollectionUtil.isNullOrEmpty(pushNoticeAppSearchEngineerQuery.getPushNoticeAppPutPlatList())
                && CollectionUtil.isNullOrEmpty(pushNoticeAppSearchEngineerQuery.getPushNoticeAppPutCities())
                && CollectionUtil.isNullOrEmpty(pushNoticeAppSearchEngineerQuery.getPushNoticeAppPutCompanyTypes())
                && CollectionUtil.isNullOrEmpty(pushNoticeAppSearchEngineerQuery.getPushNoticeAppPutCounties())
                && CollectionUtil.isNullOrEmpty(pushNoticeAppSearchEngineerQuery.getPushNoticeAppPutProvinces()) && CollectionUtil.isNullOrEmpty(pushNoticeAppSearchEngineerQuery.getEngineerIdList());

        List<Integer> engineerIdList = new ArrayList<>();
        // 根据配置的条件查询出满足的工程师
        if (!meetQuery) {

            engineerIdList = Optional.ofNullable(pushNoticeAppService.listPushNoticeToEngineer(pushNoticeAppSearchEngineerQuery)).orElse(Collections.emptyList());
        }
        return engineerIdList;
    }

    /**
     * 描述: 推送消息到app
     *
     * @param noticeId 推送消息Id
     * @param operator 操作员
     * @author wangjie
     * @since 2020/3/30
     **/
    @Override
    @ReadOnlyConnection
    public void submitPushMsgToApp(Integer noticeId, String operator) {

        PushNoticeApp pushNoticeApp = Optional.ofNullable(pushNoticeAppService.findByKey(noticeId)).orElse(new PushNoticeApp());

        if (!Objects.equals(pushNoticeApp.getPutType(), PushConsts.PUT_TYPE_PUSH_MSG)) {
            log.info("[{}],推送消息到app状态不符合,putType:{}", TAG, pushNoticeApp.getPutType());
            return;
        }
        if (!Objects.equals(pushNoticeApp.getStatus(), GlobalConsts.YES)) {
            log.info("[{}],推送消息到数据状态不符合,status:{}", TAG, pushNoticeApp.getStatus());
            return;
        }
        List<PushNoticeAppPutApp> pushAppList = Optional.ofNullable(pushNoticeAppPutAppService.listByNoticeId(noticeId)).orElse(Collections.emptyList()).stream()
                .filter(ff -> Objects.equals(ff.getStatus(), GlobalConsts.YES)).collect(Collectors.toList());
        if (CollectionUtil.isNullOrEmpty(pushAppList)) {
            log.info("[{}],推送消息到App状态不符合,接受App为null}", TAG);
            return;
        }
        List<Integer> integerList = Optional.ofNullable(this.listPushNoticeToEngineer(pushNoticeApp.getId(), null)).orElse(Collections.emptyList());
        final String pushAppTag = "10";
        pushAppList.forEach(pushAppItem -> integerList.forEach(item -> {
            String ticker = pushNoticeApp.getPicLink();
            ResultDTO resultDTO;
            switch (pushAppItem.getPutApp()) {
                case PushConsts.ZMN_APP_ANDROID:
                    resultDTO = MQPushUtil.sendAndroidInfo(item.toString(), pushNoticeApp.getPutContent(), pushNoticeApp.getPutName(), ticker, pushAppTag, String.valueOf(GlobalConsts.PLAT_MARK_ZMN));
                    if (!resultDTO.getStatusBool()) {
                        log.error("[{}],android家修汇消息发送失败。msg:{}", TAG, resultDTO.getMessage());
                    }
                    break;
                case PushConsts.YEYX_APP_ANDROID:
                    resultDTO = MQPushUtil.sendAndroidInfo(item.toString(), pushNoticeApp.getPutContent(), pushNoticeApp.getPutName(), ticker, pushAppTag, String.valueOf(GlobalConsts.PLAT_MARK_YEYX));
                    if (!resultDTO.getStatusBool()) {
                        log.error("[{}],android言而有信消息发送失败。msg:{}", TAG, resultDTO.getMessage());
                    }
                    break;
                case PushConsts.SAAS_APP_ANDROID:
                    resultDTO = MQPushUtil.sendAndroidInfo(item.toString(), pushNoticeApp.getPutContent(), pushNoticeApp.getPutName(), ticker, pushAppTag, String.valueOf(GlobalConsts.PLAT_MARK_SAAS));
                    if (!resultDTO.getStatusBool()) {
                        log.error("[{}],android一步维修消息发送失败。msg:{}", TAG, resultDTO.getMessage());
                    }
                    break;
                case PushConsts.CNHB_APP_ANDROID:
                    resultDTO = MQPushUtil.sendAndroidInfo(item.toString(), pushNoticeApp.getPutContent(), pushNoticeApp.getPutName(), ticker, pushAppTag, String.valueOf(GlobalConsts.PLAT_MARK_CNHB));
                    if (!resultDTO.getStatusBool()) {
                        log.error("[{}],android川南环保消息发送失败。msg:{}", TAG, resultDTO.getMessage());
                    }
                    break;
                case PushConsts.ZMN_APP_IOS:
                    resultDTO = MQPushUtil.sendIOSInfo(item.toString(), pushNoticeApp.getPutContent(), pushNoticeApp.getPutName(), ticker, pushAppTag, String.valueOf(GlobalConsts.PLAT_MARK_ZMN));
                    if (!resultDTO.getStatusBool()) {
                        log.error("[{}],ios家修汇消息发送失败。msg:{}", TAG, resultDTO.getMessage());
                    }
                    break;
                case PushConsts.YEYX_APP_IOS:
                    resultDTO = MQPushUtil.sendIOSInfo(item.toString(), pushNoticeApp.getPutContent(), pushNoticeApp.getPutName(), ticker, pushAppTag, String.valueOf(GlobalConsts.PLAT_MARK_YEYX));
                    if (!resultDTO.getStatusBool()) {
                        log.error("[{}],ios言而有信消息发送失败。msg:{}", TAG, resultDTO.getMessage());
                    }
                    break;
                default:
                    break;
            }
        }));
        log.info("[{}],app公告推送消息定时任务执行成功,time:{},operator:{},接受人数:{},推送app数：{}", TAG, pushNoticeApp.getBeginTime(), operator, integerList.size(), pushAppList.size());
        pushNoticeAppService.updateStatusByKeys(Collections.singletonList(noticeId), GlobalConsts.NO, operator);
    }

    /**
     * 描述: 获取app推送公告
     *
     * @param engineerId 工程师id
     * @param putType    推送类型
     * @param putApp     推送app
     * @return com.zmn.common.dto2.ResponseDTO<com.zmn.plat.dubbo.dto.push.PushNoticeAppDRO>
     * @author wangjie
     * @since 2020/3/31
     **/
    @Override
    public PushNoticeAppDRO listPushNoticeApp(Integer engineerId, Integer putType, Integer putApp) {

        PushNoticeApp pushNoticeApps = pushNoticeAppService.findPushByValidData(putType, DateUtil.getNow(), GlobalConsts.YES, putApp);
        if (Objects.isNull(pushNoticeApps)) {
            log.error("未配置app公告数据: engineerId: {},putType: {} ,putApp: {}", engineerId, putType, putApp);
            return null;
            //throw new PlatException("未配置app公告数据");
        }
        Integer noticeId = pushNoticeApps.getId();
        PushNoticeAppDRO noticeMapDro = BeanMapper.map(pushNoticeApps, PushNoticeAppDRO.class);
        noticeMapDro.setNoticeId(noticeId);
        List<Integer> engineerIdList = this.listPushNoticeToEngineer(noticeId, engineerId);
        log.info("#PushNoticeAppBService#listPushNoticeApp# count: {} engineerId: {}", engineerIdList.size(), engineerId);

        if (StringUtil.isBlank(noticeMapDro.getPicLink())) {
            noticeMapDro.setIsJump(GlobalConsts.NO);
        } else {
            noticeMapDro.setIsJump(GlobalConsts.YES);
        }
        if (engineerIdList.contains(engineerId)) {
            noticeMapDro.setPutOn(GlobalConsts.YES);
        } else {
            noticeMapDro = new PushNoticeAppDRO();
        }
        log.info("#PushNoticeAppBService#listPushNoticeApp# noticeMapDro: {} ", noticeMapDro);
        return noticeMapDro;
    }

    @Override
    public void modifyBatchStatusToNo() {

        List<Integer> noticeIdList = Optional.ofNullable(pushNoticeAppService.listPushNoticeLessTimeAndStatus(DateUtil.getNow(), GlobalConsts.YES)).orElse(Collections.emptyList()).stream()
                .map(PushNoticeApp::getId).distinct().collect(Collectors.toList());

        ListUtils.partition(noticeIdList, 200).forEach(items -> {
            pushNoticeAppService.updateStatusByKeys(items, GlobalConsts.NO, "system");
        });
    }

}
